#include <iostream>
#include <cstdio>
using namespace std;

int main(){
	int a,b;
	cin>>a>>b;
	int ans=1;
	for(int i=1;i<=b;i++){
		ans=ans*a;
		ans%=10;
	} 
	cout<<ans;
	return 0;
}
